<html>
 <head>
 <title>Documentation</title>
 </head>
 <body>

<style>
.
</style>


 <div id="wikicontent">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>

 <td class="vt" id="wikimaincol" width="100%">

 <div id="wikiheader" style="margin-bottom:1em">

 </div>
 <h1><a name="API_Reference"></a>API Reference<a href="#API_Reference" class="section_anchor"></a></h1><h2><a name="Exceptions"></a>Exceptions<a href="#Exceptions" class="section_anchor"></a></h2><p>psutil.<strong>NoSuchProcess</strong><font size="3"><strong><tt>(</tt></strong></font><i>pid, name=None, msg=None</i><font size="3"><strong><tt>)</tt></strong></font> <blockquote>Raised when no process with the given PID was found in the current process list or when a process no longer exists (zombie).
</blockquote></p><blockquote><i>Changed in 0.2.0: <tt>pid</tt>, <tt>name</tt> and <tt>msg</tt> arguments were added </i>
</blockquote><p>psutil.<strong>AccessDenied</a></strong><font size="3"><strong><tt>(</tt></strong></font><i>pid=None, name=None, msg=None</i><font size="3"><strong><tt>)</tt></strong></font> <blockquote>Raised when permission to perform an action is denied.
</blockquote></p><blockquote><i>Changed in 0.2.0: <tt>pid</tt>, <tt>name</tt> and <tt>msg</tt> arguments were added </i>
</blockquote><hr/><h2><a name="Classes"></a>Classes<a href="#Classes" class="section_anchor"></a></h2><p>psutil.<strong>Process</strong><font size="3"><strong><tt>(</tt></strong></font><i>pid</i><font size="3"><strong><tt>)</tt></strong></font> </p><blockquote>A class which represents an OS process.
</blockquote><ul><li><strong>pid</strong><br>The process pid. </li></ul><ul><li><strong>ppid</strong><br>The process parent pid. </li></ul><ul><li><strong>parent</strong><br>Return the parent process as a <tt>Process</tt> object. If no ppid is known then return <tt>None</tt>. </li></ul><ul><li><strong>name</strong><br>The process name. </li></ul><ul><li><strong>exe</strong><br>The process executable as an absolute path name. </li></ul><blockquote><i>New in 0.2.0</i>
</blockquote><ul><li><strong>cmdline</strong><br>The command line process has been called with. </li></ul><ul><li><strong>path</strong><br>The process path.  </li></ul><blockquote><i>Deprecated in 0.2.0</i>
</blockquote><ul><li><strong>create_time</strong><br> The process creation time as a floating point number expressed in seconds since the epoch, in <a href="http://en.wikipedia.org/wiki/Coordinated_Universal_Time" rel="nofollow">UTC</a>. </li></ul><ul><li><strong>uid</strong><br>The real user id of the current process.  Where uid doesn&#x27;t make sense (<i>Windows</i>) always return <tt>-1</tt>. </li></ul><ul><li><strong>gid</strong><br>The real group id of the current process.  Where gid doesn&#x27;t make sense (<i>Windows</i>) always return <tt>-1</tt>. </li></ul><ul><li><strong>username</strong><br>The name of the user that owns the process. </li></ul><blockquote><i>Changed in 2.0: Windows implementation has been rewritten in C for performace and <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">pywin32</a> extension is no longer required.</i>
</blockquote><ul><li><strong>getcwd</strong><font size="3"><strong><tt>()</tt></strong></font><br>Return a string representing the process current working directory. </li></ul><ul><li><strong>get_num_threads</strong><font size="3"><strong><tt>()</tt></strong></font><br>Return the number of threads used by this process. </li></ul><blockquote><i>New in 0.2.0</i>
</blockquote><ul><li><strong>get_cpu_times</strong><font size="3"><strong><tt>()</tt></strong></font><br>Return a tuple whose values are process CPU user and system times which means the amount of time expressed in seconds that a process has spent in <a href="http://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1" rel="nofollow">user/system mode</a>. </li></ul><ul><li><strong>cpu_percent</strong><font size="3"><strong><tt>(</tt></strong></font><i>interval=0.1</i><font size="3"><strong><tt>)</tt></strong></font><br>Return a float representing the process CPU utilization as a percentage. When interval is &gt; 0.0 compares process times to system CPU times elapsed before and after the interval (blocking). When interval is 0.0 or None compares process times to system CPU times elapsed since last call, returning immediately. In this case is recommended for accuracy that this function be called with at least 0.1 seconds between calls. </li></ul><blockquote><i>Changed in 0.2.0: interval parameter was added</i>
</blockquote><ul><li><strong>get_memory_info</strong><font size="3"><strong><tt>()</tt></strong></font><br>Return a tuple representing <a href="http://en.wikipedia.org/wiki/Resident_Set_Size" rel="nofollow">RSS</a> (Resident Set Size) and VMS (Virtual Memory Size) in bytes.<br>On UNIX RSS and VMS are the same values shown by ps. On Windows RSS and VMS refer to &quot;Mem Usage&quot; and &quot;VM Size&quot; columns of taskmgr.exe. </li></ul><ul><li><strong>get_memory_percent</strong><font size="3"><strong><tt>()</tt></strong></font><br>Compare physical system memory to process resident memory and calculate process memory utilization as a percentage. </li></ul><ul><li><strong>get_children</strong><font size="3"><strong><tt>()</tt></strong></font><br>Return the children of this process as a list of <tt>Process</tt> objects. </li></ul><blockquote><i>New in 0.2.0</i>
</blockquote><ul><li><strong>get_open_files</strong><font size="3"><strong><tt>()</tt></strong></font><br>Return files opened by process as a list of <a href="http://docs.python.org/library/collections.html?highlight=namedtuple#collections.namedtuple" rel="nofollow">namedtuples</a> including file absolute path name and file descriptor. On <strong>OSX</strong> and <strong>FreeBSD</strong> this is done by parsing <a href="http://en.wikipedia.org/wiki/Lsof" rel="nofollow">lsof</a> command output. If lsof is not installed on the system <a href="http://docs.python.org/library/exceptions.html?highlight=notimplementederror#exceptions.NotImplementedError" rel="nofollow">NotImplementedError</a> exception is raised.  Example: </li><pre class="prettyprint">&gt;&gt;&gt; import psutil, os
&gt;&gt;&gt; f = open(&#x27;file.ext&#x27;, &#x27;w&#x27;)
&gt;&gt;&gt; psutil.Process(os.getpid()).get_open_files()
[openfile(path=&#x27;/home/giampaolo/svn/psutil/file.ext&#x27;, fd=3)]</pre></ul><blockquote><i>New in 0.2.0</i>
</blockquote><ul><li><strong>get_connections</strong><font size="3"><strong><tt>()</tt></strong></font><br>Return all TCP and UPD connections opened by process as a list of <a href="http://docs.python.org/library/collections.html?highlight=namedtuple#collections.namedtuple" rel="nofollow">namedtuples</a>. Every namedtuple provides 6 attributes:<br></br> </li><ul><li><strong>fd</strong>: the socket file descriptor. This can be passed to <a href="http://docs.python.org/library/socket.html#socket.fromfd" rel="nofollow">socket.fromfd</a> to obtain a usable socket object. This is only available on UNIX; on Windows <tt>-1</tt> is always returned.<br> </li><li><strong>family</strong>: the address family, either <a href="http://docs.python.org/library/socket.html#socket.AF_INET" rel="nofollow">AF_INET</a> or <a href="http://docs.python.org/library/socket.html#socket.AF_INET6" rel="nofollow">AF_INET6</a> <br> </li><li><strong>type</strong>: the address type, either <a href="http://docs.python.org/library/socket.html#socket.SOCK_STREAM" rel="nofollow">SOCK_STREAM</a> or <a href="http://docs.python.org/library/socket.html#socket.SOCK_DGRAM" rel="nofollow">SOCK_DGRAM</a> <br> </li><li><strong>local_address</strong>: the local address as a <tt>(ip, port)</tt> tuple. <br> </li><li><strong>remote_address</strong>: the remote address as a <tt>(ip, port)</tt> tuple. When the remote endpoint is not connected the tuple is empty. <br> </li><li><strong>status</strong>: a string representing the TCP connections status. String values are supposed to match Linux&#x27;s <a href="http://students.mimuw.edu.pl/lxr/source/include/net/tcp_states.h" rel="nofollow">tcp_states.h</a> header file across all platforms. For UDP sockets this is always going to be an empty string.<br> </li></ul></ul><blockquote>Example:
<pre class="prettyprint">&gt;&gt;&gt; p = psutil.Process(1694)
&gt;&gt;&gt; p.name
&#x27;firefox&#x27;
&gt;&gt;&gt; p.get_connections()
[connection(fd=115, family=2, type=1, local_address=(&#x27;10.0.0.1&#x27;, 48776), remote_address=(&#x27;93.186.135.91&#x27;, 80), status=&#x27;ESTABLISHED&#x27;),
 connection(fd=117, family=2, type=1, local_address=(&#x27;10.0.0.1&#x27;, 43761), remote_address=(&#x27;72.14.234.100&#x27;, 80), status=&#x27;CLOSING&#x27;),
 connection(fd=119, family=2, type=1, local_address=(&#x27;10.0.0.1&#x27;, 60759), remote_address=(&#x27;72.14.234.104&#x27;, 80), status=&#x27;ESTABLISHED&#x27;),
 connection(fd=123, family=2, type=1, local_address=(&#x27;10.0.0.1&#x27;, 51314), remote_address=(&#x27;72.14.234.83&#x27;, 443), status=&#x27;SYN_SENT&#x27;)]</pre>On <strong>OSX</strong> and <strong>FreeBSD</strong> this is implemented by parsing <a href="http://en.wikipedia.org/wiki/Lsof" rel="nofollow">lsof</a> command output. If lsof is not installed on the system <a href="http://docs.python.org/library/exceptions.html?highlight=notimplementederror#exceptions.NotImplementedError" rel="nofollow">NotImplementedError</a> exception is raised. For third party processes (different than <tt>os.getpid()</tt>) results can differ depending on user privileges.<br>
</blockquote><blockquote><i>New in 0.2.0</i>
</blockquote><ul><li><strong>is_running</strong><font size="3"><strong><tt>()</tt></strong></font><br>Return whether the current process is running in the current process list. </li></ul><ul><li><strong>suspend</strong><font size="3"><strong><tt>()</tt></strong></font><br>Suspend process execution. </li></ul><ul><li><strong>resume</strong><font size="3"><strong><tt>()</tt></strong></font><br>Resume process execution. </li></ul><ul><li><strong>terminate</strong><font size="3"><strong><tt>()</tt></strong></font><br>Terminate the process with <tt>SIGTERM</tt> signal. On Windows this is an alias for <tt>kill()</tt>. </li></ul><blockquote><i>New in 0.2.0</i>
</blockquote><ul><li><strong>send_signal</strong><font size="3"><strong><tt>(</tt></strong></font><i>signal</i><font size="3"><strong><tt>)</tt></strong></font><br>Send a signal to process (see <a href="http://docs.python.org/library/signal.html" rel="nofollow">signal module</a> constants). On Windows only <tt>SIGTERM</tt> is valid and is treated as an alias for <tt>kill()</tt>. </li></ul><blockquote><i>New in 0.2.0</i>
</blockquote><ul><li><strong>kill</strong><font size="3"><strong><tt>()</tt></strong></font><br>Kill the current process by using <tt>SIGKILL</tt> signal. </li></ul><blockquote><i>Changed in 0.2.0: no longer accepts <tt>sig</tt> keyword argument - use <tt>send_signal()</tt> instead. </i>
</blockquote><hr/><h2><a name="Functions"></a>Functions<a href="#Functions" class="section_anchor"></a></h2><p>psutil.<strong>get_pid_list</strong><font size="3"><strong><tt>()</tt></strong></font><br> <blockquote>Return a list of current running PIDs.
</blockquote></p><p>psutil.<strong>pid_exists</strong><font size="3"><strong><tt>(</tt></strong></font><i>pid</i><font size="3"><strong><tt>)</tt></strong></font><br> <blockquote>Check whether the given PID exists in the current process list.
</blockquote></p><p>psutil.<strong>process_iter</strong><font size="3"><strong><tt>()</tt></strong></font><br> <blockquote>Return an iterator yielding a Process class instances for all running processes on the local machine.
</blockquote></p><hr/><h2><a name="System_related_objects"></a>System related objects<a href="#System_related_objects" class="section_anchor"></a></h2><p>psutil.<strong>cpu_percent</strong><font size="3"><strong><tt>(</tt></strong></font><i>interval=0.1</i><font size="3"><strong><tt>)</tt></strong></font><br> <blockquote>Return a float representing the current system-wide CPU utilization as a percentage. When interval is &gt; 0.0 compares system CPU times elapsed before and after the interval (blocking). When interval is 0.0 or None compares system CPU times elapsed since last call or module import, returning immediately. In this case is recommended for accuracy that this function be called with at least 0.1 seconds between calls.
</blockquote></p><blockquote><i>Changed in 0.2.0: interval parameter was added</i>
</blockquote><p>psutil.<strong>cpu_times</strong><font size="3"><strong><tt>()</tt></strong></font><br> <blockquote>Return system CPU times as a <tt>CPUTimes</tt> class object. Every CPU time is accessible in form of a <tt>CPUTimes</tt> attribute and represents the time CPU has spent in the given mode.<br>The attributes availability varies depending on the platform.  Here follows a list of all available attributes:
</blockquote></p><blockquote>- <strong>user</strong><br>
- <strong>system</strong><br>
- <strong>idle</strong><br>
- <strong>nice</strong> <i>(UNIX)</i><br>
- <strong>iowait</strong> <i>(Linux)</i><br>
- <strong>irq</strong> <i>(Linux, FreeBSD)</i><br>
- <strong>softirq</strong> <i>(Linux)</i><br>
</blockquote><p>psutil.<strong>TOTAL_PHYMEM</strong><br> psutil.<strong>avail_phymem</strong><font size="3"><strong><tt>()</tt></strong></font><br> psutil.<strong>used_phymem</strong><font size="3"><strong><tt>()</tt></strong></font><br> <blockquote>Return the amount of total, available and used physical memory on the system, in bytes.
</blockquote></p><p>psutil.<strong>cached_phymem</strong><font size="3"><strong><tt>()</tt></strong></font><br> <blockquote>Return the amount of cached memory on the system, in bytes. This reflects the &quot;cached&quot; column of free command line utility on Linux.
</blockquote></p><blockquote><i>New in 0.2.0</i><br><i>Availability: <strong>Linux</strong></i>
</blockquote><p>psutil.<strong>phymem_buffers</strong><font size="3"><strong><tt>()</tt></strong></font><br> <blockquote>Return the amount of physical memory buffers used by the kernel in bytes. This reflects the &quot;buffers&quot; column of free command line utility on Linux.
</blockquote></p><blockquote><i>New in 0.2.0</i><br><i>Availability: <strong>Linux</strong></i>
</blockquote><p>psutil.<strong>total_virtmem</strong><font size="3"><strong><tt>()</tt></strong></font><br> psutil.<strong>avail_virtmem</strong><font size="3"><strong><tt>()</tt></strong></font><br> psutil.<strong>used_virtmem</strong><font size="3"><strong><tt>()</tt></strong></font><br> <blockquote>Return the amount of total, available and used virtual memory on the system, in bytes.<br>On Linux they match the values returned by <tt>free</tt> command line utility. On OS X and FreeBSD they represent the same values as returned by <tt>sysctl vm.vmtotal</tt>. On Windows they are determined by reading the <tt>*PageFile</tt> values of <a href="http://msdn.microsoft.com/en-us/library/aa366770(VS.85).aspx" rel="nofollow">MEMORYSTATUSEX</a> structure.
</blockquote></p>
 </td>
 </tr>
 </table>
 </div>


 </body>
</html>

